﻿/****************************** Module Header ******************************\
 * Module Name:  ExMethodForButton.cs
 * Module Version:  1.0.0 (2012-8-8)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used for ExMethodForButton. 
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;

namespace UCF.Core.Forms
{
    public static class ExMethodForButton
    {
        /// <summary>
        /// 按钮上鼠标 移入、移出、按下、弹起背景图片
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="bgImgs">顺序依次是：NormalImage,MoveImage,ClickImage</param>
        /// <param name="bgColors">顺序依次是：Normal,Move,Click</param>
        /// <param name="bgClick"></param>
        public static void SetBackgroundImage(this Button btn, Image[] bgImgs, Color[] bgColors = null)
        {
            btn.FlatStyle = FlatStyle.Flat;
            btn.FlatAppearance.BorderSize = 0;
            btn.BackColor = bgColors.Get(0, Color.Transparent);
            btn.BackgroundImageLayout = ImageLayout.Center;
            btn.BackgroundImage = bgImgs.Get(0);
            /*btn.MouseHover += delegate(object sender, EventArgs e) { ((Button)sender).BackgroundImage = bgImgs.Get(1); ((Button)sender).BackColor = bgColors.Get(1, Color.Transparent); };
            btn.MouseEnter += delegate(object sender, EventArgs e) { ((Button)sender).BackgroundImage = bgImgs.Get(1); ((Button)sender).BackColor = bgColors.Get(1, Color.Transparent); };
            btn.MouseLeave += delegate(object sender, EventArgs e) { ((Button)sender).BackgroundImage = bgImgs.Get(0); ((Button)sender).BackColor = bgColors.Get(0, Color.Transparent); };
            if (bgImgs.Get(0) != null) btn.MouseDown += delegate(object sender, MouseEventArgs e) { ((Button)sender).BackgroundImage = bgImgs.Get(2); ((Button)sender).BackColor = bgColors.Get(2, Color.Transparent); };
            btn.MouseUp += delegate(object sender, MouseEventArgs e) { ((Button)sender).BackgroundImage = bgImgs.Get(0); ((Button)sender).BackColor = bgColors.Get(0, Color.Transparent); };
             */
        }
    }
}
